import { baseURL } from './config.js';

export function topList() {
    return new Promise(function (resolve, reject) {
        uni.request({
            url: `${baseURL}/toplist/detail`,
            method: 'GET',
            data: {},
            success: res => {
                console.log('接口返回数据:', res.data); // 输出接口返回数据
                let result = res.data.list;
                if (result) {
                    resolve(result.splice(0, 4));
                } else {
                    console.error('接口返回数据中没有 list 属性');
                    reject(new Error('接口返回数据中没有 list 属性'));
                }
            },
            fail: (err) => {
                console.log(err);
                reject(err);
            },
            complete: () => { }
        });
    });
}

// 封装 /toplist
export const getToplist = () => {
    return service.get('/toplist');
};

// 封装 /playlist/detail?id=${listId}
export const getPlaylistDetail = (listId) => {
    return service.get(`/playlist/detail?id=${listId}`);
};

// 封装 /song/detail?ids=${id}
export const getSongDetail = (id) => {
    return service.get(`/song/detail?ids=${id}`);
};

// 封装 /song/url?id=${id}
export const getSongUrl = (id) => {
    return service.get(`/song/url?id=${id}`);
};

// 封装 /lyric?id=${id}
export const getLyric = (id) => {
    return service.get(`/lyric?id=${id}`);
};

// 封装 /simi/song?id=${id}
export const getSimilarSongs = (id) => {
    return service.get(`/simi/song?id=${id}`);
};

// 封装 /comment/music?id=${id}
export const getSongComments = (id) => {
    return service.get(`/comment/music?id=${id}`);
};

// 封装 /search/hot/detail
export const getHotSearchDetail = () => {
    return service.get('/search/hot/detail');
};

// 封装 /search/suggest?keywords=${keywords}
export const getSearchSuggest = (keywords) => {
    return service.get(`/search/suggest?keywords=${keywords}`);
};